package com.jhd.fuzhou.view.dossier;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.jhd.fuzhou.R;
import com.jhd.fuzhou.service.DossierService;
import com.jhd.fuzhou.service.LoginService;
import com.jhd.fuzhou.service.SpecialService;
import com.jhd.fuzhou.service.SupervisionService;
import com.jhd.fuzhou.util.CustomToast;
import com.jhd.fuzhou.util.DateTime;
import com.jhd.fuzhou.util.EditTextView;
import com.jhd.fuzhou.util.SaveSupervisionInspection;
import com.jhd.fuzhou.util.StartProcess;
import com.jhd.fuzhou.util.TextDialog;
import com.jhd.fuzhou.util.UploadFile;
import com.jhd.fuzhou.util.UtilHelper;
import com.jhd.fuzhou.view.daily.DailyChooseCompanyActivity;
import com.jhd.fuzhou.view.daily.DailyStepTwoActivity;
import com.jhd.fuzhou.view.login.BaseActivity;
import com.jhd.fuzhou.view.login.SignatureView;
import com.jhd.fuzhou.view.mail.MailListDeptActivity;
import com.jhd.fuzhou.vo.CheckValue;
import com.jhd.fuzhou.vo.CountyVo;
import com.jhd.fuzhou.vo.DepartDetail;
import com.jhd.fuzhou.vo.DeptVo;
import com.jhd.fuzhou.vo.DialogShow;
import com.jhd.fuzhou.vo.GlobalDictionaryVo;
import com.jhd.fuzhou.vo.JsonForResult;
import com.jhd.fuzhou.vo.MajorSpeciality;
import com.jhd.fuzhou.vo.MinorSpeciality;
import com.jhd.fuzhou.vo.OrganizationVo;
import com.jhd.fuzhou.vo.PersonInfoVo;
import com.jhd.fuzhou.vo.SupervisedUnitVo;
import com.jhd.fuzhou.vo.Supervisor;

import net.zigin.commons.util.ParamsMapUtil;
import net.zigin.commons.util.StringUtil;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

import static com.jhd.fuzhou.util.EditTextView.TextViewChange;
import static com.jhd.fuzhou.util.StartProcess.start;
import static com.jhd.fuzhou.view.login.MainActivity.supervisionInspectionVo;

public class DossierUpdateActivity extends BaseActivity {
    @BindView(R.id.title)
    TextView title;//标题
    @BindView(R.id.tv_specialityCategory)
    TextView tv_specialityCategory;//所属专业
    @BindView(R.id.tv_specialityDetail)
    TextView tv_specialityDetail;//主营项目
    @BindView(R.id.tv_economic_type)
    TextView tv_economic_type;//经济类型
    @BindView(R.id.tv_register_area)
    TextView tv_register_area;//注册地址所在地区
    @BindView(R.id.tv_manage_area)
    TextView tv_manage_area;//经营地址所在地区
    @BindView(R.id.tv_regulator)
    TextView tv_regulator;//监管机构
    @BindView(R.id.tv_supervision_department)
    TextView tv_supervision_department;//监管科室
    @BindView(R.id.tv_nation)
    TextView tv_nation;//民族
    @BindView(R.id.tv_identity_type)
    TextView tv_identity_type;//身份证件类型
    @BindView(R.id.tv_grade)
    TextView tv_grade;//主营量化等级
    @BindView(R.id.tv_report_person)
    TextView tv_report_person;//报告人
    @BindView(R.id.et_certificate_no)
    EditText et_certificate_no;//社会信用代码
    @BindView(R.id.et_unit)
    EditText et_unit;//被监督单位
    @BindView(R.id.et_register_address)
    EditText et_register_address;//注册地址
    @BindView(R.id.et_manage_address)
    EditText et_manage_address;//经营地址
    @BindView(R.id.et_legal_person)
    EditText et_legal_person;//法人
    @BindView(R.id.et_position)
    EditText et_position;//职务
    @BindView(R.id.et_identity_no)
    EditText et_identity_no;//证件号码
    @BindView(R.id.et_contact)
    EditText et_contact;//联系人
    @BindView(R.id.et_contact_phone)
    EditText et_contact_phone;//联系电话
    @BindView(R.id.et_postal_code)
    EditText et_postal_code;//邮政编码

    @BindView(R.id.btn_relate)
    Button btn_relate;//关联单位
    @BindView(R.id.btn_specialityDetail)
    Button btn_specialityDetail;//专业明细标题
    @BindView(R.id.btn_save)
    Button btn_save;//保存
    @BindView(R.id.rb_status_1)
    RadioButton rb_status_1;//性别男
    @BindView(R.id.rb_status_2)
    RadioButton rb_status_2;//性别女
    @BindView(R.id.rb_status_3)
    RadioButton rb_status_3;//营业状况正常
    @BindView(R.id.rb_status_4)
    RadioButton rb_status_4;//营业状况关闭
    @BindView(R.id.rb_status_5)
    RadioButton rb_status_5;//营业状况暂停

    @BindView(R.id.rel_specialityCategory)
    RelativeLayout rel_specialityCategory;//所属专业
    @BindView(R.id.rel_specialityDetail)
    RelativeLayout rel_specialityDetail;//主营项目
    @BindView(R.id.rel_economic_type)
    RelativeLayout rel_economic_type;//经济类型
    @BindView(R.id.rel_register_area)
    RelativeLayout rel_register_area;//注册地址所在地区
    @BindView(R.id.rel_manage_area)
    RelativeLayout rel_manage_area;//经营地址所在地区
    @BindView(R.id.rel_regulator)
    RelativeLayout rel_regulator;//监管机构
    @BindView(R.id.rel_supervision_department)
    RelativeLayout rel_supervision_department;//监管科室
    @BindView(R.id.rel_nation)
    RelativeLayout rel_nation;//民族
    @BindView(R.id.rel_identity_type)
    RelativeLayout rel_identity_type;//身份证件类型
    @BindView(R.id.rel_grade)
    RelativeLayout rel_grade;//主营量化等级
    @BindView(R.id.rel_report_person)
    RelativeLayout rel_report_person;//报告人
    private Context context = this;
    private AlertDialog _alertDialog;
    private List<DialogShow> personList = new ArrayList<>();//报告人
    private List<DialogShow> economicTypeList = new ArrayList<>();//经济类型
    private List<DialogShow> nationList = new ArrayList<>();//民族
    private List<DialogShow> identityTypeList = new ArrayList<>();//身份证件类型
    private List<DialogShow> organizationVoList = new ArrayList<>();//监督机构
    private List<DialogShow> majorSpecialityList = new ArrayList<>();//所属专业
    private List<DialogShow> minorSpecialityList = new ArrayList<>();//专业明细
    private List<DialogShow> mainQuantizationLevelList = new ArrayList<>();//量化等级
    private String [] mainQuantizationLevels=new String[]{"A级","B级","C级","不予评级","未评级"};
    private List<DialogShow> deptVoList = new ArrayList<>();//监督部门
    private SupervisedUnitVo supervisedUnitVo;
    private String reportDate;
    private List<CountyVo> countyVoList;
    private String id;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.activity_dossier_update);
    }

    @Override
    protected void processLogic() {
        onBack();
        id = getIntent().getStringExtra("id");
        reportDate = DateTime.getTodayDate();//获取今天的日期作为报告日期
        getCheckValue();//查询数据字典中的经济类型，民族，身份证类型
        getMajorSpecialitySelector();
        getOrgSelector();
        getCountySelector();
        setMainQuantizationLevelList();
        if (id == null) {//说明是来新加的
            title.setText("添加本底档案");
            supervisedUnitVo = new SupervisedUnitVo();
            supervisedUnitVo.setSuperviseOrgId(application.getOrgId());
            supervisedUnitVo.setSuperviseSector(application.getOrgName());
            tv_regulator.setText(application.getOrgName());
            TextViewChange(tv_regulator,context);
            supervisedUnitVo.setSuperviseDeptId(application.getDeptId());
            supervisedUnitVo.setSuperviseOffice(application.getDeptName());
            tv_supervision_department.setText(application.getDeptName());
            TextViewChange(tv_supervision_department,context);
            supervisedUnitVo.setReportDate(reportDate);
            rb_status_3.setChecked(true);
            supervisedUnitVo.setBusinessStatus("1");//新建默认正常
        } else {//说明来修改的
            getSupervisedUnitById(id);
            title.setText("修改本底档案");
        }
    }

    private void setMainQuantizationLevelList(){
        for(int i=0;i<mainQuantizationLevels.length;i++){
            DialogShow dialogShow=new DialogShow();
            dialogShow.setName(mainQuantizationLevels[i]);
            mainQuantizationLevelList.add(dialogShow);
        }
    }

    @OnClick({R.id.et_certificate_no, R.id.et_unit, R.id.et_register_address, R.id.et_manage_address, R.id.et_legal_person, R.id.et_position, R.id.et_identity_no,
            R.id.et_contact, R.id.et_contact_phone, R.id.et_postal_code, R.id.btn_relate, R.id.btn_save, R.id.rb_status_1, R.id.rb_status_2,
            R.id.rb_status_3, R.id.rb_status_4, R.id.rb_status_5, R.id.rel_specialityCategory,
            R.id.rel_specialityDetail, R.id.rel_economic_type, R.id.rel_register_area, R.id.rel_manage_area,
            R.id.rel_regulator, R.id.rel_supervision_department, R.id.rel_nation, R.id.rel_identity_type, R.id.rel_report_person})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.et_certificate_no:
                TextDialog.creditCode(context, "社会信用代码", et_certificate_no);
                break;
            case R.id.et_unit:
                TextDialog.showDialog(context, "被监督单位", et_unit);
                break;
            case R.id.et_register_address:
                TextDialog.showDialog(context, "注册地址", et_register_address);
                break;
            case R.id.et_manage_address:
                TextDialog.showDialog(context, "经营地址", et_manage_address);
                break;
            case R.id.et_legal_person:
                TextDialog.showDialog(context, "法定代表人", et_legal_person);
                break;
            case R.id.et_position:
                TextDialog.showDialog(context, "职务", et_position);
                break;
            case R.id.et_identity_no:
                if(tv_identity_type.getText().toString().equals("请选择身份证件类型")){
                    CustomToast.showText(context, "请先选择身份证件类型", 3000, 0, 0).show();
                }else{
                    if(tv_identity_type.getText().toString().equals("居民身份证")){
                        TextDialog.showCertificateDialog2(context, "证件号码", et_identity_no, rb_status_1, rb_status_2);
                    }else{
                        TextDialog.showDialog(context, tv_identity_type.getText().toString(), et_identity_no);
                    }
                }
                break;
            case R.id.et_contact:
                TextDialog.showDialog(context, "联系人", et_contact);
                break;
            case R.id.et_contact_phone:
                TextDialog.showDialog2(context, "联系电话", et_contact_phone);
                break;
            case R.id.et_postal_code:
                TextDialog.showDialog2(context, "邮政编码", et_postal_code);
                break;
            case R.id.btn_relate://关联单位
                String certificate_no = et_certificate_no.getText().toString().trim();
                if (certificate_no.length() != 18) {
                    CustomToast.showText(context, "请输入18位社会信用代码", 3000, 0, 0).show();
                } else {
                    getSupervisedUnitList(certificate_no);
                }
                break;
            case R.id.btn_save://先设置不可点击
                btn_save.setClickable(false);
                if("".equals(et_certificate_no.getText().toString().trim())){
                    CustomToast.showText(context, "社会信用代码为必填项", 3000, 0, 0).show();
                    btn_save.setClickable(true);
                    break;
                }
                if("请选择所属专业".equals(tv_specialityCategory.getText().toString().trim())){
                    CustomToast.showText(context, "所属专业为必选项", 3000, 0, 0).show();
                    btn_save.setClickable(true);
                    break;
                }
                if(tv_specialityDetail.getText().toString().trim().contains("请选择")){
                    CustomToast.showText(context, "主营项目为必选项", 3000, 0, 0).show();
                    btn_save.setClickable(true);
                    break;
                }
                if("".equals(et_unit.getText().toString().trim())){
                    CustomToast.showText(context, "被监督单位为必填项", 3000, 0, 0).show();
                    btn_save.setClickable(true);
                    break;
                }
                if("请选择注册地址所在地区".equals(tv_register_area.getText().toString().trim())){
                    CustomToast.showText(context, "注册地址所在地区为必选项", 3000, 0, 0).show();
                    btn_save.setClickable(true);
                    break;
                }
                if("".equals(et_register_address.getText().toString().trim())){
                    CustomToast.showText(context, "注册地址为必填项", 3000, 0, 0).show();
                    btn_save.setClickable(true);
                    break;
                }
                if("请选择经营地址所在地区".equals(tv_manage_area.getText().toString().trim())){
                    CustomToast.showText(context, "经营地址所在地区为必选项", 3000, 0, 0).show();
                    btn_save.setClickable(true);
                    break;
                }
                if("".equals(et_manage_address.getText().toString().trim())){
                    CustomToast.showText(context, "经营地址为必填项", 3000, 0, 0).show();
                    btn_save.setClickable(true);
                    break;
                }
                if("请选择监管机构".equals(tv_regulator.getText().toString().trim())){
                    CustomToast.showText(context, "监管机构为必选项", 3000, 0, 0).show();
                    btn_save.setClickable(true);
                    break;
                }
                if("".equals(et_legal_person.getText().toString().trim())){
                    CustomToast.showText(context, "法定代表人为必填项", 3000, 0, 0).show();
                    btn_save.setClickable(true);
                    break;
                }
                if(!rb_status_3.isChecked()&&!rb_status_4.isChecked()&&!rb_status_5.isChecked()){
                    CustomToast.showText(context, "经营状况为必选项", 3000, 0, 0).show();
                    btn_save.setClickable(true);
                }
                save();
                break;
            case R.id.rb_status_1:
                supervisedUnitVo.setGender("男");
                break;
            case R.id.rb_status_2:
                supervisedUnitVo.setGender("女");
                break;
            case R.id.rb_status_3:
                supervisedUnitVo.setBusinessStatus("1");
                break;
            case R.id.rb_status_4:
                supervisedUnitVo.setBusinessStatus("0");
                break;
            case R.id.rb_status_5:
                supervisedUnitVo.setBusinessStatus("2");
                break;
            case R.id.rel_specialityCategory:
                if(id==null){
                    dialogShow(tv_specialityCategory, "所属专业", majorSpecialityList);
                }
                break;
            case R.id.rel_specialityDetail:
                dialogShow(tv_specialityDetail, "主要经营项目", minorSpecialityList);
                break;
            case R.id.rel_economic_type:
                dialogShow(tv_economic_type, "经济类型", economicTypeList);
                break;
            case R.id.rel_register_area:
                dialogCountyShow(tv_register_area, "注册地址所在地区");
                break;
            case R.id.rel_manage_area:
                dialogCountyShow(tv_manage_area, "经营地址所在地区");
                break;
            case R.id.rel_regulator:
                dialogShow(tv_regulator, "监管机构", organizationVoList);
                break;
            case R.id.rel_supervision_department:
                dialogShow(tv_supervision_department, "监管科室", deptVoList);
                break;
            case R.id.rel_nation:
                dialogShow(tv_nation, "民族", nationList);
                break;
            case R.id.rel_identity_type:
                dialogShow(tv_identity_type, "证件类型", identityTypeList);
                break;
            case R.id.rel_report_person:
                dialogShow(tv_report_person, "报告人", personList);
                break;
            case R.id.rel_grade:
                dialogShow(tv_grade, "主营量化等级", mainQuantizationLevelList);
                break;
        }
    }

    public void save() {
        Retrofit retrofit = UtilHelper.retrofit(application, UtilHelper.baseUrls.API());//URL的头
        DossierService vs = retrofit.create(DossierService.class);
        Map<String, Object> params = new LinkedHashMap<String, Object>();
        params.put("creditCode",supervisedUnitVo.getCreditCode());
        params.put("specialityCategory",supervisedUnitVo.getSpecialityCategory());
        params.put("specialityCategoryId",supervisedUnitVo.getSpecialityCategoryId());
        params.put("legalRepresentative",et_legal_person.getText().toString().trim());
        if(supervisedUnitVo.getSpecialityDetail()!=null)params.put("specialityDetail",supervisedUnitVo.getSpecialityDetail());
        if(supervisedUnitVo.getSpecialityDetailId()!=null)params.put("specialityDetailId",supervisedUnitVo.getSpecialityDetailId());
        if(supervisedUnitVo.getMainQuantizationLevel()!=null)params.put("mainQuantizationLevel",supervisedUnitVo.getMainQuantizationLevel());
        if(supervisedUnitVo.getEconomicType()!=null)params.put("economicType",supervisedUnitVo.getEconomicType());
        params.put("unitName",et_unit.getText().toString().trim());
        params.put("unitNo",supervisedUnitVo.getUnitNo());
        params.put("registerCity",supervisedUnitVo.getRegisterCity());
        params.put("registerCounty",supervisedUnitVo.getRegisterCounty());
        params.put("registerProvince",supervisedUnitVo.getRegisterProvince());
        params.put("registerAddress",supervisedUnitVo.getRegisterAddress());
        params.put("managementCity",supervisedUnitVo.getManagementCity());
        params.put("managementCounty",supervisedUnitVo.getManagementCounty());
        params.put("managementProvince",supervisedUnitVo.getManagementProvince());
        params.put("superviseSector",supervisedUnitVo.getSuperviseSector());
        params.put("superviseOrgId",supervisedUnitVo.getSuperviseOrgId());
        params.put("businessStatus",supervisedUnitVo.getBusinessStatus());
        params.put("reportDate",supervisedUnitVo.getReportDate());
        params.put("reportPerson",application.getName());
        params.put("isPc",1);
        if(id!=null)params.put("id",id);
        if(supervisedUnitVo.getSuperviseDeptId()!=null)params.put("superviseDeptId",supervisedUnitVo.getSuperviseDeptId());
        if(supervisedUnitVo.getSuperviseOffice()!=null)params.put("superviseOffice",supervisedUnitVo.getSuperviseOffice());
        if(supervisedUnitVo.getCertificateType()!=null)params.put("certificateType",supervisedUnitVo.getCertificateType());
        if(supervisedUnitVo.getGender()!=null)params.put("gender",supervisedUnitVo.getGender());
        if(supervisedUnitVo.getNation()!=null)params.put("nation",supervisedUnitVo.getNation());
        if(!"".equals(et_identity_no.getText().toString().trim()))params.put("certificateNo",et_identity_no.getText().toString().trim());
        if(!"".equals(et_position.getText().toString().trim()))params.put("position",et_position.getText().toString().trim());
        if(!"".equals(et_contact.getText().toString().trim()))params.put("contactPerson",et_contact.getText().toString().trim());
        if(!"".equals(et_contact_phone.getText().toString().trim()))params.put("contactNumber",et_contact_phone.getText().toString().trim());
        if(!"".equals(et_postal_code.getText().toString().trim()))params.put("postalCode",et_postal_code.getText().toString().trim());
        if(!"".equals(et_register_address.getText().toString().trim()))params.put("registerAddress",et_register_address.getText().toString().trim());
        if(!"".equals(et_manage_address.getText().toString().trim()))params.put("managementAddress",et_manage_address.getText().toString().trim());
        if(!"".equals(et_certificate_no.getText().toString().trim()))params.put("creditCode",et_certificate_no.getText().toString().trim());
        RequestBody requestBody = RequestBody.create(MediaType.parse("Content-Type, application/json"), JSON.toJSONString(params));
        String json=JSON.toJSONString(params);
        Call<JsonForResult> jsonForResultCall = vs.saveSupervisedUnit(application.getAccessToken(), requestBody);
        jsonForResultCall.enqueue(new Callback<JsonForResult>() {
            @Override
            public void onResponse(Call<JsonForResult> call, Response<JsonForResult> response) {
                try {
                    JsonForResult jsonForResult = response.body();
                    String ss=(id!=null)?"修改本底档案":"添加本底档案";
                    if (jsonForResult != null && jsonForResult.isSuccess()) {
                        CustomToast.showText(context, ss+"成功！", 3000, 0, 0).show();
                        setResult(1);
                        finish();
                    } else {
                        if(jsonForResult.getMessage()!=null){
                            CustomToast.showText(context,jsonForResult.getMessage(), 3000, 0, 0).show();
                        }else{
                            CustomToast.showText(context, ss+"失败！", 3000, 0, 0).show();
                        }
                        btn_save.setClickable(true);
                    }
                } catch (Exception e) {
                    UtilHelper.alertMsg(context, "错误", e.getMessage());
                    btn_save.setClickable(true);
                }
            }

            @Override
            public void onFailure(Call<JsonForResult> call, Throwable t) {
                String msg =(id!=null)? "修改本底档案失败!":"添加本底档案失败！";
                UtilHelper.alertMsg(context, "错误", msg);
                btn_save.setClickable(true);
            }
        });

    }

    //获取获取监管机构
    private void getOrgSelector() {
        Retrofit retrofit = UtilHelper.retrofit(application, UtilHelper.baseUrls.API());//URL的头
        LoginService vs = retrofit.create(LoginService.class);
        Call<JsonForResult> jsonForResultCall = vs.getOrgSelector(application.getAccessToken());//调用接口获取json返回
        jsonForResultCall.enqueue(new Callback<JsonForResult>() {
            @Override
            public void onResponse(Call<JsonForResult> call, Response<JsonForResult> response) {
                try {
                    JsonForResult jsonForResult = (JsonForResult) response.body();
                    if (jsonForResult != null && jsonForResult.isSuccess()) {
                        List<OrganizationVo> organizationVoLists = JSON.parseArray(jsonForResult.getData().toString(), OrganizationVo.class);
                        organizationVoList.clear();
                        for (OrganizationVo organizationVo : organizationVoLists) {
                            DialogShow dialogShow = new DialogShow();
                            dialogShow.setId(organizationVo.getId());
                            dialogShow.setName(organizationVo.getName());
                            organizationVoList.add(dialogShow);
                        }
                    } else {
                        UtilHelper.alertMsg(context, "错误", jsonForResult.getMessage());
                    }
                } catch (Exception e) {
                    CustomToast.showText(context, e.getLocalizedMessage(), 3000, 0, 0).show();
                }
            }

            @Override
            public void onFailure(Call<JsonForResult> call, Throwable t) {
                String msg = "网络错误!";
                if (StringUtil.isNullOrEmpty(t.getMessage()) == false) msg = msg + t.getMessage();
                UtilHelper.alertMsg(context, "错误", msg);
            }
        });
    }

    private void getDeptVoSelector() {
        Retrofit retrofit = UtilHelper.retrofit(application, UtilHelper.baseUrls.API());//URL的头
        SpecialService vs = retrofit.create(SpecialService.class);
        Map<String, String> params = ParamsMapUtil.getInstance("orgId", StringUtil.isNullOrEmpty(supervisedUnitVo.getSuperviseOrgId()) ? "" : supervisedUnitVo.getSuperviseOrgId());
        Call<JsonForResult> jsonForResultCall = vs.getDeptSelector(application.getAccessToken(), params);//调用接口获取json返回
        jsonForResultCall.enqueue(new Callback<JsonForResult>() {
            @Override
            public void onResponse(Call<JsonForResult> call, Response<JsonForResult> response) {
                try {
                    JsonForResult jsonForResult = (JsonForResult) response.body();
                    if (jsonForResult != null && jsonForResult.isSuccess()) {
                        List<DeptVo> deptVos = JSON.parseArray(jsonForResult.getData().toString(), DeptVo.class);
                        deptVoList.clear();
                        for (DeptVo deptVo : deptVos) {
                            DialogShow dialogShow = new DialogShow();
                            dialogShow.setId(deptVo.getId());
                            dialogShow.setName(deptVo.getName());
                            deptVoList.add(dialogShow);
                        }
                    } else {
                        UtilHelper.alertMsg(context, "错误", jsonForResult.getMessage());
                    }
                } catch (Exception e) {
                    CustomToast.showText(context, e.getLocalizedMessage(), 3000, 0, 0).show();
                }
            }

            @Override
            public void onFailure(Call<JsonForResult> call, Throwable t) {
                String msg = "网络错误!";
                if (StringUtil.isNullOrEmpty(t.getMessage()) == false) msg = msg + t.getMessage();
                UtilHelper.alertMsg(context, "错误", msg);
            }
        });
    }

    private void setUnitVo(SupervisedUnitVo supervisedUnitVo) {
        getDeptVoSelector();getMinorSpecialitySelector();
        if(supervisedUnitVo.getBusinessStatus()!=null){
            if("1".equals(supervisedUnitVo.getBusinessStatus())){
                rb_status_3.setChecked(true);
            }else if("0".equals(supervisedUnitVo.getBusinessStatus())){
                rb_status_4.setChecked(true);
            }else if("2".equals(supervisedUnitVo.getBusinessStatus())){
                rb_status_5.setChecked(true);
            }
        }
        if(supervisedUnitVo.getCertificateType()!=null)tv_identity_type.setText(supervisedUnitVo.getCertificateType());
        TextViewChange(tv_identity_type,context);
        if(supervisedUnitVo.getCertificateNo()!=null)et_identity_no.setText(supervisedUnitVo.getCertificateNo());
        if(supervisedUnitVo.getPosition()!=null)et_position.setText(supervisedUnitVo.getPosition());
        if(supervisedUnitVo.getNation()!=null)tv_nation.setText(supervisedUnitVo.getNation());
        TextViewChange(tv_nation,context);
        if(supervisedUnitVo.getCreditCode()!=null)et_certificate_no.setText(supervisedUnitVo.getCreditCode());
        if(supervisedUnitVo.getEconomicType()!=null)tv_economic_type.setText(supervisedUnitVo.getEconomicType());
        TextViewChange(tv_economic_type,context);
        if(supervisedUnitVo.getGender()!=null) {
            if("女".equals(supervisedUnitVo.getGender())){
                rb_status_2.setChecked(true);
            }else if("男".equals(supervisedUnitVo.getGender())){
                rb_status_1.setChecked(true);
            }
        }
        if(supervisedUnitVo.getLegalRepresentative()!=null)et_legal_person.setText(supervisedUnitVo.getLegalRepresentative());
        if(supervisedUnitVo.getManagementAddress()!=null)et_manage_address.setText(supervisedUnitVo.getManagementAddress());
        if(supervisedUnitVo.getRegisterAddress()!=null)et_register_address.setText(supervisedUnitVo.getRegisterAddress());
        if(supervisedUnitVo.getSpecialityCategory()!=null){
            rel_specialityDetail.setVisibility(View.VISIBLE);
            tv_specialityCategory.setText(supervisedUnitVo.getSpecialityCategory());
            TextViewChange(tv_specialityCategory,context);
            if(supervisedUnitVo.getSpecialityCategory().equals("公共场所")){
                btn_specialityDetail.setText("主要经营项目");
                tv_specialityDetail.setText("请选择"+btn_specialityDetail.getText().toString());
            }else if(supervisedUnitVo.getSpecialityCategory().equals("学校卫生")){
                btn_specialityDetail.setText("学校类别");
                tv_specialityDetail.setText("请选择"+btn_specialityDetail.getText().toString());
            }else{
                btn_specialityDetail.setText("单位类别");
                tv_specialityDetail.setText("请选择"+btn_specialityDetail.getText().toString());
            }
        }
        if(supervisedUnitVo.getSpecialityDetail()!=null)tv_specialityDetail.setText(supervisedUnitVo.getSpecialityDetail());
        TextViewChange(tv_specialityDetail,context);
        if(supervisedUnitVo.getSuperviseOffice()!=null)tv_supervision_department.setText(supervisedUnitVo.getSuperviseOffice());
        TextViewChange(tv_supervision_department,context);
        if(supervisedUnitVo.getSuperviseSector()!=null)tv_regulator.setText(supervisedUnitVo.getSuperviseSector());
        TextViewChange(tv_regulator,context);
        if(supervisedUnitVo.getUnitName()!=null)et_unit.setText(supervisedUnitVo.getUnitName());
        if(supervisedUnitVo.getRegisterCounty()!=null)tv_register_area.setText(supervisedUnitVo.getRegisterCounty());
        TextViewChange(tv_register_area,context);
        if(supervisedUnitVo.getManagementCounty()!=null)tv_manage_area.setText(supervisedUnitVo.getManagementCounty());
        TextViewChange(tv_manage_area,context);
        if(supervisedUnitVo.getContactPerson()!=null)et_contact.setText(supervisedUnitVo.getContactPerson());
        if(supervisedUnitVo.getContactNumber()!=null)et_contact_phone.setText(supervisedUnitVo.getContactNumber());
        if(supervisedUnitVo.getPostalCode()!=null)et_postal_code.setText(supervisedUnitVo.getPostalCode());
    }

    //获取地区列表
    private void getCountySelector() {
        Retrofit retrofit = UtilHelper.retrofit(application, UtilHelper.baseUrls.API());//URL的头
        SpecialService vs = retrofit.create(SpecialService.class);
        Map<String, String> params = ParamsMapUtil.getInstance("cityCode", "361000");
        Call<JsonForResult> jsonForResultCall = vs.getCountySelector(application.getAccessToken(), params);//调用接口获取json返回
        jsonForResultCall.enqueue(new Callback<JsonForResult>() {
            @Override
            public void onResponse(Call<JsonForResult> call, Response<JsonForResult> response) {
                try {
                    JsonForResult jsonForResult = (JsonForResult) response.body();
                    if (jsonForResult != null && jsonForResult.isSuccess()) {
                        countyVoList = JSON.parseArray(jsonForResult.getData().toString(), CountyVo.class);
                    } else {
                        UtilHelper.alertMsg(context, "错误", jsonForResult.getMessage());
                    }
                } catch (Exception e) {
                    CustomToast.showText(context, e.getLocalizedMessage(), 3000, 0, 0).show();
                }
            }

            @Override
            public void onFailure(Call<JsonForResult> call, Throwable t) {
                String msg = "网络错误!";
                if (StringUtil.isNullOrEmpty(t.getMessage()) == false) msg = msg + t.getMessage();
                UtilHelper.alertMsg(context, "错误", msg);
            }
        });
    }

    public class CountyVoAdapter extends RecyclerView.Adapter<CountyVoAdapter.ViewHolder> {
        private TextView textView;
        private int checkPosition = -1;

        public CountyVoAdapter(TextView textView) {
            this.textView = textView;
        }

        @NonNull
        @Override
        public CountyVoAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_question_choose, parent, false);
            CountyVoAdapter.ViewHolder viewHolder = new CountyVoAdapter.ViewHolder(itemView);
            return viewHolder;
        }

        @Override
        public void onBindViewHolder(@NonNull CountyVoAdapter.ViewHolder holder, int position) {
            holder.tv_choose.setText(countyVoList.get(position).getName());
            if (countyVoList.get(position).getName().equals(textView.getText().toString())) {
                holder.image.setVisibility(View.VISIBLE);
            } else {
                holder.image.setVisibility(View.GONE);
            }
            holder.relativeLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    textView.setText(countyVoList.get(position).getName());
                    TextViewChange(textView, context);
                    holder.image.setVisibility(View.VISIBLE);
                    _alertDialog.dismiss();
                    checkPosition = position;
                    notifyDataSetChanged();
                    if (textView == tv_register_area) {
                        supervisedUnitVo.setRegisterProvince(application.getProvince());
                        supervisedUnitVo.setRegisterCity(application.getCity());
                        supervisedUnitVo.setRegisterCounty(countyVoList.get(position).getName());
                    } else if (textView == tv_manage_area) {
                        supervisedUnitVo.setManagementProvince(application.getProvince());
                        supervisedUnitVo.setManagementCity(application.getCity());
                        supervisedUnitVo.setManagementCounty(countyVoList.get(position).getName());
                    }
                }
            });
            if (position == checkPosition) {
                holder.image.setVisibility(View.VISIBLE);
            } else {
                if (checkPosition != -1) {
                    holder.image.setVisibility(View.GONE);
                }
            }
        }

        @Override
        public int getItemCount() {
            return countyVoList.size();
        }

        class ViewHolder extends RecyclerView.ViewHolder {
            TextView tv_choose;
            ImageView image;
            RelativeLayout relativeLayout;

            public ViewHolder(View itemView) {
                super(itemView);
                this.tv_choose = itemView.findViewById(R.id.tv_choose);
                this.image = itemView.findViewById(R.id.image);
                this.relativeLayout = itemView.findViewById(R.id.relativeLayout);
            }
        }
    }

    private void getSupervisedUnitList(String creditCode) {
        Retrofit retrofit = UtilHelper.retrofit(application, UtilHelper.baseUrls.API());//URL的头
        SupervisionService vs = retrofit.create(SupervisionService.class);
        Map<String, Object> params =  new LinkedHashMap<String, Object>();
        params.put("creditCode", creditCode);
        if(!("1".equals(application.getOrgLevel()))){
            if(application.getOrgId()!=null)params.put("superviseOrgId",application.getOrgId());
        }
        Call<JsonForResult> jsonForResultCall = vs.getSupervisedUnitList(application.getAccessToken(),params);//调用接口获取json返回
        jsonForResultCall.enqueue(new Callback<JsonForResult>() {
            @Override
            public void onResponse(Call<JsonForResult> call, Response<JsonForResult> response) {
                try {
                    JsonForResult jsonForResult = (JsonForResult) response.body();
                    if (jsonForResult != null && jsonForResult.isSuccess()) {
                        if (jsonForResult.getData() != null) {
                            List<SupervisedUnitVo> supervisedUnitVos = JSON.parseArray(jsonForResult.getData().toString(), SupervisedUnitVo.class);
                            supervisedUnitVo=supervisedUnitVos.get(0);
                            supervisedUnitVo.setReportDate(reportDate);
                            setUnitVo(supervisedUnitVos.get(0));
                        } else {
                            getDepartDetailsByCreditCode(creditCode);
                        }
                    } else {
                        UtilHelper.alertMsg(context, "错误", jsonForResult.getMessage());
                    }
                } catch (Exception e) {
//                    CustomToast.showText(context,e.getLocalizedMessage(),3000,0,0).show();
                }
            }

            @Override
            public void onFailure(Call<JsonForResult> call, Throwable t) {

            }
        });
    }

    private void getDepartDetailsByCreditCode(String creditCode) {
        Retrofit retrofit = UtilHelper.retrofit(application, UtilHelper.baseUrls.API());//URL的头
        DossierService vs = retrofit.create(DossierService.class);
        Map<String, String> params = ParamsMapUtil.getInstance("creditCode", StringUtil.isNullOrEmpty(creditCode) ? "" : creditCode);
        Call<JsonForResult> jsonForResultCall = vs.getDepartDetailsByCreditCode(application.getAccessToken(), params);//调用接口获取json返回
        jsonForResultCall.enqueue(new Callback<JsonForResult>() {
            @Override
            public void onResponse(Call<JsonForResult> call, Response<JsonForResult> response) {
                try {
                    JsonForResult jsonForResult = (JsonForResult) response.body();
                    if (jsonForResult != null && jsonForResult.isSuccess()) {
                        if (jsonForResult.getData() != null) {
                            DepartDetail departDetail = JSON.parseObject(jsonForResult.getData().toString(), DepartDetail.class);
                            setDepart(departDetail);
                        } else {
                            CustomToast.showText(context, "未查到可关联的信息!", 3000, 0, 0).show();
                        }

                    } else {
                        UtilHelper.alertMsg(context, "错误", jsonForResult.getMessage());
                    }
                } catch (Exception e) {
                    CustomToast.showText(context, e.getLocalizedMessage(), 3000, 0, 0).show();
                }
            }

            @Override
            public void onFailure(Call<JsonForResult> call, Throwable t) {
                String msg = "网络错误!";
                if (StringUtil.isNullOrEmpty(t.getMessage()) == false) msg = msg + t.getMessage();
                UtilHelper.alertMsg(context, "错误", msg);
            }
        });
    }

    private void setDepart(DepartDetail departDetail) {
        if(departDetail.getUnitName()!=null){
            et_unit.setText(departDetail.getUnitName());supervisedUnitVo.setUnitName(departDetail.getUnitName());
        }
        if(departDetail.getUnitNo()!=null)supervisedUnitVo.setUnitNo(departDetail.getUnitNo());
        if(departDetail.getRegisterAddress()!=null||departDetail.getManagementAddress()!=null){
            String address=(departDetail.getRegisterAddress()==null)?departDetail.getManagementAddress():departDetail.getRegisterAddress();
            et_register_address.setText(address);et_manage_address.setText(address);
        }
        if(departDetail.getEconomicType()!=null){
            tv_economic_type.setText(departDetail.getEconomicType());supervisedUnitVo.setEconomicType(departDetail.getEconomicType());
        }
        if(departDetail.getLegalRepresentative()!=null){
            et_legal_person.setText(departDetail.getLegalRepresentative());supervisedUnitVo.setLegalRepresentative(departDetail.getLegalRepresentative());
        }
    }
    //报告人，暂时先不处理
    /*private void getPersonInfoList(String deptId,String orgId){
        Retrofit retrofit = UtilHelper.retrofit(application, UtilHelper.baseUrls.API());//URL的头
        LoginService vs = retrofit.create(LoginService.class);
        Map<String, String> params = ParamsMapUtil.getInstance("deptId", StringUtil.isNullOrEmpty(deptId)?"":deptId).addParam("orgId",StringUtil.isNullOrEmpty(orgId)?"":orgId);
        Call<JsonForResult> jsonForResultCall = vs.getPersonInfoList(application.getAccessToken(),params);//调用接口获取json返回
        jsonForResultCall.enqueue(new Callback<JsonForResult>() {
            @Override
            public void onResponse(Call<JsonForResult> call, Response<JsonForResult> response) {
                try {
                    JsonForResult jsonForResult = (JsonForResult) response.body();
                    if (jsonForResult != null && jsonForResult.isSuccess()) {
                        if(jsonForResult.getData()!=null){
                            List<PersonInfoVo> personInfoVoList = JSON.parseArray(jsonForResult.getData().toString(), PersonInfoVo.class);
                            personList.clear();
                            for (PersonInfoVo personInfoVo : personInfoVoList) {
                                DialogShow dialogShow=new DialogShow();
                                dialogShow.setId(personInfoVo.getId());
                                dialogShow.setName(personInfoVo.getName());
                                personList.add(dialogShow);
                            }
                        }

                    } else {
                        UtilHelper.alertMsg(context, "错误", jsonForResult.getMessage());
                    }
                } catch (Exception e) {
                    CustomToast.showText(context,e.getLocalizedMessage(),3000,0,0).show();
                }
            }

            @Override
            public void onFailure(Call<JsonForResult> call, Throwable t) {
                String msg = "网络错误!";
                if (StringUtil.isNullOrEmpty(t.getMessage()) == false) msg = msg + t.getMessage();
                UtilHelper.alertMsg(context, "错误", msg);
            }
        });
    }*/

    private void getSupervisedUnitById(String id) {
        Retrofit retrofit = UtilHelper.retrofit(application, UtilHelper.baseUrls.API());//URL的头
        SupervisionService vs = retrofit.create(SupervisionService.class);
        Map<String, String> params = ParamsMapUtil.getInstance("id", id);
        Call<JsonForResult> jsonForResultCall = vs.getSupervisedUnitById(application.getAccessToken(), params);//调用接口获取json返回
        jsonForResultCall.enqueue(new Callback<JsonForResult>() {
            @Override
            public void onResponse(Call<JsonForResult> call, Response<JsonForResult> response) {
                try {
                    JsonForResult jsonForResult = (JsonForResult) response.body();
                    if (jsonForResult != null && jsonForResult.isSuccess()) {
                        supervisedUnitVo = JSON.parseObject(jsonForResult.getData().toString(), SupervisedUnitVo.class);
                        supervisedUnitVo.setReportDate(reportDate);
                        setUnitVo(supervisedUnitVo);
                    } else {
                        UtilHelper.alertMsg(context, "错误", jsonForResult.getMessage());
                    }
                } catch (Exception e) {
                    CustomToast.showText(context, e.getLocalizedMessage(), 3000, 0, 0).show();
                }
            }

            @Override
            public void onFailure(Call<JsonForResult> call, Throwable t) {
                String msg = "网络错误!";
                if (StringUtil.isNullOrEmpty(t.getMessage()) == false) msg = msg + t.getMessage();
                UtilHelper.alertMsg(context, "错误", msg);
            }
        });
    }

    //获取所属专业列表
    private void getMajorSpecialitySelector() {
        Retrofit retrofit = UtilHelper.retrofit(application, UtilHelper.baseUrls.API());//URL的头
        SupervisionService vs = retrofit.create(SupervisionService.class);
        Call<JsonForResult> jsonForResultCall = vs.getMajorSpecialitySelector(application.getAccessToken());//调用接口获取json返回
        jsonForResultCall.enqueue(new Callback<JsonForResult>() {
            @Override
            public void onResponse(Call<JsonForResult> call, Response<JsonForResult> response) {
                try {
                    JsonForResult jsonForResult = (JsonForResult) response.body();
                    if (jsonForResult != null && jsonForResult.isSuccess()) {
                        List<MajorSpeciality> majorSpecialitys = JSON.parseArray(jsonForResult.getData().toString(), MajorSpeciality.class);
                        majorSpecialityList.clear();
                        for (MajorSpeciality majorSpeciality : majorSpecialitys) {
                            DialogShow dialogShow = new DialogShow();
                            dialogShow.setId(majorSpeciality.getId());
                            dialogShow.setName(majorSpeciality.getName());
                            majorSpecialityList.add(dialogShow);
                        }
                    } else {
                        UtilHelper.alertMsg(context, "错误", jsonForResult.getMessage());
                    }
                } catch (Exception e) {
                    CustomToast.showText(context, e.getLocalizedMessage(), 3000, 0, 0).show();
                }
            }

            @Override
            public void onFailure(Call<JsonForResult> call, Throwable t) {
                String msg = "网络错误!";
                if (StringUtil.isNullOrEmpty(t.getMessage()) == false) msg = msg + t.getMessage();
                UtilHelper.alertMsg(context, "错误", msg);
            }
        });
    }

    //根据所属专业的Id获取专业明细列表
    private void getMinorSpecialitySelector() {
        Retrofit retrofit = UtilHelper.retrofit(application, UtilHelper.baseUrls.API());//URL的头
        SupervisionService vs = retrofit.create(SupervisionService.class);
        Map<String, String> params = ParamsMapUtil.getInstance("parentId", StringUtil.isNullOrEmpty(supervisedUnitVo.getSpecialityCategoryId()) ? "" : supervisedUnitVo.getSpecialityCategoryId());
        Call<JsonForResult> jsonForResultCall = vs.getMinorSpecialitySelector(application.getAccessToken(), params);//调用接口获取json返回
        jsonForResultCall.enqueue(new Callback<JsonForResult>() {
            @Override
            public void onResponse(Call<JsonForResult> call, Response<JsonForResult> response) {
                try {
                    JsonForResult jsonForResult = (JsonForResult) response.body();
                    if (jsonForResult != null && jsonForResult.isSuccess()) {
                        if (jsonForResult.getData() == null) {
                            minorSpecialityList.clear();
                        } else {
                            List<MinorSpeciality> minorSpecialitys = JSON.parseArray(jsonForResult.getData().toString(), MinorSpeciality.class);
                            minorSpecialityList.clear();
                            for (MinorSpeciality minorSpeciality : minorSpecialitys) {
                                DialogShow dialogShow = new DialogShow();
                                dialogShow.setId(minorSpeciality.getId());
                                dialogShow.setName(minorSpeciality.getName());
                                dialogShow.setCode(minorSpeciality.getCode());
                                minorSpecialityList.add(dialogShow);
                            }
                        }
                    } else {
                        UtilHelper.alertMsg(context, "错误", jsonForResult.getMessage());
                    }
                } catch (Exception e) {
                    CustomToast.showText(context, e.getLocalizedMessage(), 3000, 0, 0).show();
                }
            }

            @Override
            public void onFailure(Call<JsonForResult> call, Throwable t) {
                String msg = "网络异常!";
                if (StringUtil.isNullOrEmpty(t.getMessage()) == false) msg = msg + t.getMessage();
                UtilHelper.alertMsg(context, "错误", msg);
            }
        });
    }

    protected void getCheckValue() {
        Retrofit retrofit = UtilHelper.retrofit(application, UtilHelper.baseUrls.UC());//URL的头
        SupervisionService vs = retrofit.create(SupervisionService.class);
        JSONArray jsonArray = new JSONArray();
        jsonArray.add("经济类型(国)");
        jsonArray.add("民族");
        jsonArray.add("身份证件类型(国)");
        Map<String, Object> params = new LinkedHashMap<String, Object>();
        params.put("nameList", jsonArray);
        RequestBody requestBody = RequestBody.create(MediaType.parse("Content-Type, application/json"),
                JSON.toJSONString(params));
        Call<JsonForResult> jsonForResultCall = vs.getValueList(application.getAccessToken(), requestBody);
        jsonForResultCall.enqueue(new Callback<JsonForResult>() {
            @Override
            public void onResponse(Call<JsonForResult> call, Response<JsonForResult> response) {
                try {
                    JsonForResult jsonForResult = response.body();
                    if (jsonForResult != null && jsonForResult.isSuccess()) {
                        //请求授权信息
                        if (jsonForResult.getData() != null) {
                            checkValue = JSON.parseArray(jsonForResult.getData().toString(), CheckValue.class);
                            for (int i = 0; i < checkValue.size(); i++) {
                                if("身份证件类型(国)".equals(checkValue.get(i).getName())){
                                    identityTypeList.clear();
                                    for (GlobalDictionaryVo globalDictionaryVo : checkValue.get(i).getGlobalDictionaryVoMap()) {
                                        DialogShow dialogShow = new DialogShow();
                                        dialogShow.setId(globalDictionaryVo.getId());
                                        dialogShow.setName(globalDictionaryVo.getValue());
                                        dialogShow.setCode(globalDictionaryVo.getKey());
                                        identityTypeList.add(dialogShow);
                                    }
                                }else if("经济类型(国)".equals(checkValue.get(i).getName())) {
                                    economicTypeList.clear();
                                    for (GlobalDictionaryVo globalDictionaryVo : checkValue.get(i).getGlobalDictionaryVoMap()) {
                                        DialogShow dialogShow = new DialogShow();
                                        dialogShow.setId(globalDictionaryVo.getId());
                                        dialogShow.setName(globalDictionaryVo.getValue());
                                        dialogShow.setCode(globalDictionaryVo.getKey());
                                        economicTypeList.add(dialogShow);
                                    }
                                }else if("民族".equals(checkValue.get(i).getName())) {
                                    nationList.clear();
                                    for (GlobalDictionaryVo globalDictionaryVo : checkValue.get(i).getGlobalDictionaryVoMap()) {
                                        DialogShow dialogShow = new DialogShow();
                                        dialogShow.setId(globalDictionaryVo.getId());
                                        dialogShow.setName(globalDictionaryVo.getValue());
                                        dialogShow.setCode(globalDictionaryVo.getKey());
                                        nationList.add(dialogShow);
                                    }
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    UtilHelper.alertMsg(getApplicationContext(), "错误", e.getMessage());
                }
            }

            @Override
            public void onFailure(Call<JsonForResult> call, Throwable t) {
                String msg = "获取检测项目失败!";
                UtilHelper.alertMsg(getApplicationContext(), "错误", msg);
            }
        });
    }

    public void dialogCountyShow(TextView textView, String title) {
        LayoutInflater mLayoutInflater = LayoutInflater.from(this);
        View view = mLayoutInflater.inflate(R.layout.dialog_person_choose, null);
        final androidx.appcompat.app.AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context, R.style.ActionSheetDialogStyle);
        alertBuilder.setView(view);
        _alertDialog = alertBuilder.create();
        //获取当前Activity所在的窗体
        Window window = _alertDialog.getWindow();
        window.setGravity(Gravity.BOTTOM);
        _alertDialog.show();
        ImageView iv_dismiss = (ImageView) view.findViewById(R.id.iv_dismiss);
        TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
        RecyclerView rv_choose = (RecyclerView) view.findViewById(R.id.rv_choose);
        RelativeLayout rel_search = (RelativeLayout) view.findViewById(R.id.rel_search);
        rel_search.setVisibility(View.GONE);
        LinearLayoutManager layoutManage = new LinearLayoutManager(context);
        rv_choose.setLayoutManager(layoutManage);
        tv_title.setText(title);//标题要改一下
        CountyVoAdapter recyclerAdapter = new CountyVoAdapter(textView);
        rv_choose.setAdapter(recyclerAdapter);
        iv_dismiss.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                _alertDialog.dismiss();
            }
        });
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = (int) (getWindowManager().getDefaultDisplay().getWidth());                     //使用这种方式更改了dialog的框宽
        window.setAttributes(params);
    }

    public void dialogShow(TextView textView, String title, List<DialogShow> dialogShowList) {
        LayoutInflater mLayoutInflater = LayoutInflater.from(this);
        View view = mLayoutInflater.inflate(R.layout.dialog_person_choose, null);
        final androidx.appcompat.app.AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context, R.style.ActionSheetDialogStyle);
        alertBuilder.setView(view);
        _alertDialog = alertBuilder.create();
        //获取当前Activity所在的窗体
        Window window = _alertDialog.getWindow();
        window.setGravity(Gravity.BOTTOM);
        _alertDialog.show();
        ImageView iv_dismiss = (ImageView) view.findViewById(R.id.iv_dismiss);
        TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
        RecyclerView rv_choose = (RecyclerView) view.findViewById(R.id.rv_choose);
        LinearLayoutManager layoutManage = new LinearLayoutManager(context);
        rv_choose.setLayoutManager(layoutManage);
        tv_title.setText(title);//标题要改一下
        EditText et_search = (EditText) view.findViewById(R.id.et_search);
        ImageView iv_cancel = (ImageView) view.findViewById(R.id.iv_cancel);
        List<DialogShow> dialogShowList2 = new ArrayList<>();//用来展示的list
        DialogShowAdapter recyclerAdapter = new DialogShowAdapter(textView, _alertDialog, dialogShowList);
        rv_choose.setAdapter(recyclerAdapter);
        et_search.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                for (DialogShow dialogShow : dialogShowList) {
                    if (dialogShow.getName().contains(s.toString())) {
                        dialogShowList2.add(dialogShow);
                    }
                }
                DialogShowAdapter recyclerAdapter = new DialogShowAdapter(textView, _alertDialog, dialogShowList2);
                rv_choose.setAdapter(recyclerAdapter);
            }
        });
        iv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                et_search.setText("");
                DialogShowAdapter recyclerAdapter = new DialogShowAdapter(textView, _alertDialog, dialogShowList2);
                rv_choose.setAdapter(recyclerAdapter);
            }
        });
        iv_dismiss.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                _alertDialog.dismiss();
            }
        });
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = (int) (getWindowManager().getDefaultDisplay().getWidth());                     //使用这种方式更改了dialog的框宽
        window.setAttributes(params);
    }

    public class DialogShowAdapter extends RecyclerView.Adapter<DialogShowAdapter.ViewHolder> {
        private List<DialogShow> dialogShowList;
        private TextView textView;
        private AlertDialog _alertDialog;
        private int checkPosition = -1;

        public DialogShowAdapter(TextView textView, AlertDialog _alertDialog, List<DialogShow> dialogShowList) {
            this.dialogShowList = dialogShowList;
            this._alertDialog = _alertDialog;
            this.textView = textView;
        }

        @NonNull
        @Override
        public DialogShowAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_question_choose, parent, false);
            DialogShowAdapter.ViewHolder viewHolder = new DialogShowAdapter.ViewHolder(itemView);
            return viewHolder;
        }

        @Override
        public void onBindViewHolder(@NonNull DialogShowAdapter.ViewHolder holder, int position) {
            holder.tv_choose.setText(dialogShowList.get(position).getName());
            if (dialogShowList.get(position).getName().equals(textView.getText().toString())) {
                holder.image.setVisibility(View.VISIBLE);
            } else {
                holder.image.setVisibility(View.GONE);
            }
            holder.relativeLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    textView.setText(dialogShowList.get(position).getName());
                    TextViewChange(textView, context);
                    holder.image.setVisibility(View.VISIBLE);
                    _alertDialog.dismiss();
                    checkPosition = position;
                    notifyDataSetChanged();
                    if (textView == tv_specialityCategory) {
                        rel_specialityDetail.setVisibility(View.VISIBLE);
                        if(!dialogShowList.get(position).getId().equals(supervisedUnitVo.getSpecialityCategoryId())){
                            supervisedUnitVo.setSpecialityDetail(null);
                            supervisedUnitVo.setSpecialityDetailId(null);
                            if(dialogShowList.get(position).getName().equals("公共场所")){
                                btn_specialityDetail.setText("主要经营项目");
                                tv_specialityDetail.setText("请选择"+btn_specialityDetail.getText().toString());
                            }else if(dialogShowList.get(position).getName().equals("学校卫生")){
                                btn_specialityDetail.setText("学校类别");
                                tv_specialityDetail.setText("请选择"+btn_specialityDetail.getText().toString());
                            }else{
                                btn_specialityDetail.setText("单位类别");
                                tv_specialityDetail.setText("请选择"+btn_specialityDetail.getText().toString());
                            }
                            tv_specialityDetail.setTextColor(getResources().getColor(R.color.search));
                        }
                        supervisedUnitVo.setSpecialityCategoryId(dialogShowList.get(position).getId());
                        supervisedUnitVo.setSpecialityCategory(dialogShowList.get(position).getName());
                        if("公共场所".equals(dialogShowList.get(position).getName())){
                            rel_grade.setVisibility(View.VISIBLE);
                        }else{
                            rel_grade.setVisibility(View.GONE);
                            tv_grade.setText("请选择主营量化等级");
                            tv_grade.setTextColor(getResources().getColor(R.color.search));
                            supervisedUnitVo.setMainQuantizationLevel(null);
                        }
                        getMinorSpecialitySelector();
                    } else if (textView == tv_specialityDetail) {
                        supervisedUnitVo.setSpecialityDetail(dialogShowList.get(position).getName());
                        supervisedUnitVo.setSpecialityDetailId(dialogShowList.get(position).getId());
                        supervisedUnitVo.setSpecialityDetailCode(dialogShowList.get(position).getCode());
                    } else if (textView == tv_regulator) {
                        if(supervisedUnitVo.getSuperviseOrgId()!=null&&!supervisedUnitVo.getSuperviseOrgId().equals(dialogShowList.get(position).getId())){
                            supervisedUnitVo.setSuperviseDeptId(null);
                            supervisedUnitVo.setSuperviseOffice(null);
                            tv_supervision_department.setText("请选择监管科室");
                            tv_supervision_department.setTextColor(getResources().getColor(R.color.search));
                        }
                        supervisedUnitVo.setSuperviseOrgId(dialogShowList.get(position).getId());
                        supervisedUnitVo.setSuperviseSector(dialogShowList.get(position).getName());
                        getDeptVoSelector();
                    } else if (textView == tv_supervision_department) {
                        supervisedUnitVo.setSuperviseDeptId(dialogShowList.get(position).getId());
                        supervisedUnitVo.setSuperviseOffice(dialogShowList.get(position).getName());
                    } else if (textView == tv_economic_type) {
                        supervisedUnitVo.setEconomicType(dialogShowList.get(position).getName());
                        supervisedUnitVo.setEconomicTypeCode(dialogShowList.get(position).getCode());
                    } else if (textView == tv_identity_type) {
                        supervisedUnitVo.setCertificateType(dialogShowList.get(position).getName());
                        supervisedUnitVo.setCertificateTypeCode(dialogShowList.get(position).getCode());
                    } else if (textView == tv_nation) {
                        supervisedUnitVo.setNation(dialogShowList.get(position).getName());
                    }else if (textView == tv_grade) {
                        supervisedUnitVo.setMainQuantizationLevel(dialogShowList.get(position).getName());
                    }
                }
            });
            if (position == checkPosition) {
                holder.image.setVisibility(View.VISIBLE);
            } else {
                if (checkPosition != -1) {
                    holder.image.setVisibility(View.GONE);
                }
            }
        }

        @Override
        public int getItemCount() {
            return dialogShowList.size();
        }

        class ViewHolder extends RecyclerView.ViewHolder {
            TextView tv_choose;
            ImageView image;
            RelativeLayout relativeLayout;

            public ViewHolder(View itemView) {
                super(itemView);
                this.tv_choose = itemView.findViewById(R.id.tv_choose);
                this.image = itemView.findViewById(R.id.image);
                this.relativeLayout = itemView.findViewById(R.id.relativeLayout);
            }
        }
    }


}